import Vue from 'vue'
import Vuex from 'vuex'
import cartModule from './modules/cart' 

Vue.use(Vuex)

const store = new Vuex.Store({
    modules: {
        cartModule,
        
    },
    state: {
        tableInfo: JSON.parse(localStorage.getItem("tableInfo"))||{},
        showDetail: false,
        visible: {
            shiftJobVisible: false, //交班
            roomVisible: false, //餐台列表
            goodsRoomVisble: false, //商品列表
            cartVisible: false, //购物车
            placeOrderVisible: false, //下单
            placeOrderComVisible: false, //新下单
            saleClearVisible: false, //沽清
            finishOrders: false,
            tableSettle: false,
            tableOrder: false,
        },
        //loginStatus: localStorage.get('loginStatus'),
    },
    mutations: {
        tableInfo (state,tableInfo) {
            localStorage.setItem("tableInfo", JSON.stringify(tableInfo))
            state.tableInfo = tableInfo
        },
        showDetail(state,isShow){
            state.showDetail = isShow
        },
        /**
         *
         * @typedef {{list:any[],show:Boolean}} singleVisible
         * @param {singleVisible} payload
         * @description list里面的内容都为show，list不含的都为!show
        */
        setMultipleVisible(state, payload) {
            let { list = [], show } = payload;
            let nameList = Object.keys(state.visible);
            nameList.forEach((key) => {
            if (list.includes(key)) {
                state.visible[key] = show;
            } else {
                state.visible[key] = !show;
            }
            });
        },
    },
    actions: {
        tableInfo ({commit},tableInfo) {
            commit('tableInfo',tableInfo)
        }
    }
})

export default store